﻿@model Tuple<List<deviceManage.Models.DeviceType>,int?>
@{
    ViewData["Title"] = "设备变更";
}
<style>
    .layui-form.search .layui-form-label {
        width: 90px;
    }
</style> 

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto search" lay-filter="app-content-list">

                    <table>
                        <tr>
                            <td>
                                <div class="layui-inline">
                                    <label class="layui-form-label">设备名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:70px;">设备编号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="deviceId" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 60px;">设备类型</label>
                                    <div class="layui-input-inline">
                                        <select name="deviceTypeId">
                                            <option></option>
                                            @foreach (var type in Model.Item1)
                                            {
                                                <option value="@type.Id">@type.Name</option>
                                            }
                                        </select>
                                    </div>
                                </div>
                            </td>
                            <td rowspan="2" style="padding-left:10px;">
                                <div class="layui-inline">
                                    <button style="height:75px;padding: 0 10px;" class="layui-btn layuiadmin-btn-list" lay-submit="" lay-filter="search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                                    </button>
                                </div>
                            </td>
                            
                        </tr>
                        <tr>
                            <td colspan="3">
                                <div class="layui-inline">
                                    <label class="layui-form-label">固定资产编号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="no" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:70px;">采购日期</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="start" class="layui-input date" id="test-laydate-start" placeholder="开始日期" lay-key="122">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:58px;">结束日期</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="end" class="layui-input date" id="test-laydate-end" placeholder="结束日期" lay-key="123">
                                    </div>
                                </div>
                            </td>
                            
                        </tr>
                    </table>

                </div>
                

                <div class="layui-card-body">
                    <div style="padding-bottom: 10px;">                                                
                    </div>
                    <table id="deviceTable" lay-filter="LAY-app-content-list"></table>
                </div>
            </div>
        </div>
  

<script type="text/javascript" src="~/js/deviceState.js"></script>
<script>
    

    var laydate = layui.laydate;
    var insStart = laydate.render({
        elem: '#test-laydate-start'
        , min: '1980-1-1'
        , done: function (value, date) {
            //更新结束日期的最小日期
            insEnd.config.min = lay.extend({}, date, {
                month: date.month - 1
            });

            //自动弹出结束日期的选择器
            insEnd.config.elem[0].focus();
        }
    });

    //结束日期
    var insEnd = laydate.render({
        elem: '#test-laydate-end'
        , min: '1980-1-1'
        , done: function (value, date) {
            //更新开始日期的最大日期
            insStart.config.max = lay.extend({}, date, {
                month: date.month - 1
            });
        }
    });

    form.render(null, 'app-content-list');

    //监听搜索
    form.on('submit(search)', function (data) {
        var field = data.field;
        //执行重载
        tableObj.reload({
            where: field
        });
    });
     

        //加载table
    var tableObj= table.render({
            elem: '#deviceTable'
        , url: '/deviceChange/list/' //模拟接口
            ,method: 'post'
            , height:"full-160"
            , page: true
        , cols: [[
            
             { field: 'deviceName', title: '设备名称', minWidth: 180, templet: '<div><a class="link" onclick="showDetail(\'{{d.id}}\')"  href="#">{{d.name}}</a></div>' }
            , { field: 'deviceType', title: '设备类型', width: 100, templet: '<div>{{ d.deviceType.name}}</div>' }
            , { field: 'model', title: '规格型号', width: 120, templet: '<div>{{ d.model}}</div>' }
            , { field: 'deviceId', title: '设备编号', width: 120, templet: '<div>{{ d.deviceId}}</div>' }
            , { field: 'name', title: '固定资产编号', width: 120, templet: '<div>{{ d.no}}</div>' }
            , { field: 'name', title: '所在机房', width: 120, templet: '<div>{{ d.room.name}}</div>' }
            , { field: 'name', title: '状态', width: 120, templet: '<div>{{ getDeviceState(d.status)}}</div>' }
            , { field: 'name', title: '采购日期', width: 120, templet: '<div>{{ getDate(d.buyDate)}}</div>' }
            , { field: 'name', title: '接管日期', width: 120, templet: '<div>{{ getDate(d.receiveDate)}}</div>' }
            , { field: 'name', title: '出保日期', width: 120, templet: '<div>{{ getDate(d.serviceDate) }}</div>' }
            , {
                field: 'opr', title: '操作', width: 200, fixed: 'right',
                templet:
                    '<div class="layui-table-cell laytable-cell-11-0-8">'
                    + ' {{ getButtons(d.id,d.status) }} '
                    + '</div>'
            }
        ]]
        , skin: 'line'
        , done: function () {
            $("td").on("mouseenter", function () {
                var cell = $(this).find(".layui-table-cell")[0];
                if (cell && cell.offsetWidth < cell.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                    layer.tips(text, that, {
                        tips: [1, "#1FBBA6"],
                        time: 2000
                    });
                }

            });
        }
        });

     var viewFlag = "@Model.Item2";
    //根据状态获取不同的按钮
    function getButtons(id, state) {      
        if (viewFlag == "1") return "";
        if (state == 1) {
            var html = ' <a class="layui-btn layui-btn-normal layui-btn-xs"  onclick="moveOut(\''+id+'\')" >设备转出</a>'                
                + '<a class="layui-btn   layui-btn-xs" onclick="transferDepart(\'' + id + '\')">设备移交</a>';        
            return html; 
        } else {
            return "";
        } 
    }

     
    

     //设备转出
     var winIndex = null;
     function moveOut(id) {
         $.get("/deviceChange/MovieOut?id="+id, function (str) {
               winIndex = layer.open({
                    type: 1,
                   title: '设备转出',
                    area:["650px","450px"],
                    content: str //注意，如果str是object，那么需要字符拼接。
               }); 
            });
    }  

    //设备转移部门
    function transferDepart(id) {
        $.get("/deviceChange/transferDepart?id=" + id, function (str) {
            winIndex = layer.open({
                type: 1,
                title: '设备移交',
                area: ["650px", "450px"],
                content: str //注意，如果str是object，那么需要字符拼接。
            });
        });
    }  

    function showDetail(id) {
        layer.open({
            mask: 0,
            type: 2,
            content: '/deviceInfo/Detail?id=' + id,
            area: ["1000px", "550px"]
        });
    }
</script>

